/*
*  Copyright (C) 2009  Peter Kist & Jan Ripke
*
*  This program is free software: you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "InterMediator.h"
#include "Detail/MediatorImpl.h"

namespace galaxy {
    namespace mediator {

        detail::MediatorImpl * InterMediator::m_Mediator;

        InterMediator::InterMediator(void)
        {
        }

        InterMediator::~InterMediator(void)
        {
        }

        void InterMediator::initialize() {
            m_Mediator = new detail::MediatorImpl();
        }

        void InterMediator::terminate() {
            if (m_Mediator) {
                delete m_Mediator;
            }
        }

        bool InterMediator::registerProducer(Producer& producer) {
            detail::MediatorImpl& mediator = InterMediator::instance ();
            return mediator.registerProducer (producer);            
        }

        bool InterMediator::unregisterProducer (int category) {
            detail::MediatorImpl& mediator = InterMediator::instance ();
            return mediator.unregisterProducer (category);
        }

        /** registers a consumer. Producers can only send events to registered consumers.
        The consumer is registered by \b consumerType and can only be registered once per consumer type. 
        @param consumer The consumer to register
        @return true upon success, false upon failure
        */
        bool InterMediator::registerConsumer(Consumer& consumer) {
            detail::MediatorImpl& mediator = InterMediator::instance ();
            return mediator.registerConsumer (consumer);
        }

        bool InterMediator::unregisterConsumer(std::string consumerType) {
            detail::MediatorImpl& mediator = InterMediator::instance ();
            return mediator.unregisterConsumer (consumerType);
        }

        bool InterMediator::registerInterest(std::string consumerType, Identifier& interest) {
            detail::MediatorImpl& mediator = InterMediator::instance ();
            return mediator.registerInterest (consumerType, interest);
        }

        bool InterMediator::unregisterInterest(std::string consumerType, Identifier& interest) {
            return false;
        }

        bool InterMediator::postEvent(Event& event, PostMethod postMethod) {
            detail::MediatorImpl& mediator = InterMediator::instance ();
            return mediator.postEvent (event, postMethod);
        }

        bool InterMediator::RequestProducer(const Request &Request, RequestResultPtr& result) {
            detail::MediatorImpl& mediator = InterMediator::instance ();
            return mediator.RequestProducer (Request, result);
        }


    } // mediator
} // galaxy
